@extends('layouts.header')
@section('content')
	@if (Auth::check()) {{-- Only logged users can create subtopics, obv --}}
    	<h3 style="text-align: center;"><a href="{{ route('new_subtopic') }} " title="Create subtopic">Create new subtopic</a></h3>
	@endif
	<form action="{{ route('list_all_topics')}}" method="GET" role="search">
    {{ csrf_field() }}
        <input type="text" name="search" placeholder="Search topics">
        <button type="submit">Search</button>
	</form>
	@if (isset($_GET['search']) and $_GET['search'])
		@foreach($topics as $topic)
			@if (Str::contains($topic->title, $_GET['search']))
				<h2><a href="{{ route('show_topic',['sub'=>$topic->title]) }} " title="Show topic">{{$topic->title}}</a></h2>
        		<h5>posts_number({{$topic->posts_number}}) / created at: {{$topic->created_at}} / last update: {{$topic->updated_at}} </h5>
				<br><br>
			@endif
		@endforeach
	@else
		@foreach($topics as $topic)
			<h2><a href="{{ route('show_topic',['sub'=>$topic->title]) }} " title="Show topic">{{$topic->title}}</a></h2>
        	<h5>posts_number({{$topic->posts_number}}) / created at: {{$topic->created_at}} / last update: {{$topic->updated_at}} </h5>
			<br><br>
		@endforeach
	@endif
@endsection()
